"""# 需求 获取https://www.baidu.com/s?wd=龙玉涛的网页源码

import urllib.request

url = "https://www.baidu.com/s?wd=龙玉涛"

#请求对象的定制
#为了解决反爬的第一手段
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0"}

request = urllib.request.Request(url = url,headers = headers)


#模拟器浏览器向服务器发送请求
response = urllib.request.urlopen(request)

#获取响应内容
content = response.read().decode("utf-8")

#打印数据
print(content)

#运行后会报错:UnicodeEncodeError: 'ascii' codec can't encode characters in position 10-12: ordinal not in range(128)
#原因是在于url中的"龙玉涛"不能使用ascii码解析
#需要将其转化为ascii码 """

#以下为完整可执行代码
import urllib.request
import urllib.parse
url = "https://www.baidu.com/s?wd="
name = urllib.parse.quote("龙玉涛")

#此时url应为url+name
url = url + name
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:126.0) Gecko/20100101 Firefox/126.0"}
request = urllib.request.Request(url=url,headers=headers)
response = urllib.request.urlopen(request)
content = response.read().decode("utf-8")

print(content)